home *** CD-ROM | disk | FTP | other *** search
/ Amiga Format CD 24 / Amiga Format AFCD24 (Feb 1998, Issue 108).iso / -in_the_mag- / emulation / -otherstuff- / amiganpi / src_blitz / amiganpi.asc next >
Text File  |  1998-01-05  |  5KB  |  197 lines

  1. ; Amiga Newton Package Installer
  2. ; version 1.4
  3.  
  4. ; DON'T set overflow checking when compiling
  5. ; as Blitz2 doesn't like trying to poke.b a,255
  6. ; (probably because 255 is an invalid signed byte value)
  7.  
  8. #debug=0
  9. #cli_only=0                   ; set to 1 if CLI-only version
  10.  
  11. CNIF #cli_only=0
  12. WBStartup
  13. CEND
  14.  
  15. ;SetErr:End:End SetErr
  16.  
  17. ; default value of variables, may be altered by CLI arguments,
  18. ; preference file or MUI interface
  19.  
  20. package$=""
  21. package_length.l=0
  22. device$="devs:serial.device"
  23. device_unit.l=0
  24. device_buffer.l=64
  25. device_speed.l=38400
  26. device_flags.l=148        ; Xon/Xoff disabled, high speed and RTS/CTS
  27. desk_wait.l=30
  28. newt_wait.l=5
  29.  
  30. INCDIR "temp:programming/AmigaNPI/"
  31. XINCLUDE "Interface.bb2"
  32.  
  33. ;strangely enough, only one DIR can be the INCDIR at a time!
  34. INCDIR "temp:programming/AmigaNPI/"
  35. XINCLUDE "crc16.bb2"
  36.  
  37. INCDIR "temp:programming/AmigaNPI/"
  38. XINCLUDE "fram.bb2"
  39.  
  40. ;main routine
  41.  
  42. lt$="newtdockdock"+Chr$(0)+Chr$(0)+Chr$(0)+Chr$(4)+Chr$(0)+Chr$(0)+Chr$(0)+Chr$(4)
  43. lt2$="newtdockstim"+Chr$(0)+Chr$(0)+Chr$(0)+Chr$(4)+Chr$(0)+Chr$(0)+Chr$(0)+Chr$(newt_wait)
  44. lt3$="newtdocklpkg"+Chr$(0)+Chr$(0)+Chr$($2f)+Chr$($a0)
  45. lt4$="newtdockdisc"+Chr$(0)+Chr$(0)+Chr$(0)+Chr$(0)
  46.  
  47. buf$=String$(" ",128)
  48.  
  49. still_running=True
  50.  
  51. CNIF #cli_only=0
  52. If gui_on Then still_running=get_gui_args{}
  53. CEND
  54.  
  55. While still_running
  56.   timeout=False
  57.   If OpenSerial (device$,device_unit,device_speed,device_flags)
  58.    SetSerialBuffer device_unit,device_buffer
  59.    If ReadFile(0,package$)
  60.     Poke.l <3$+12,Lof(0)
  61.     Notify_Waiting{}
  62.     dummy.l=waitConnection{}
  63.     If dummy<-1
  64.      timeout=True
  65.      Goto timeout_jump
  66.     EndIf
  67.     Notify_Connecting{}
  68.     dummy.l=receiveData{&buf$,Len(buf$)}    ;newtdockrtdk
  69.     If dummy<-1
  70.      timeout=True
  71.      Goto timeout_jump
  72.     EndIf
  73.     Notify_rtdk{}
  74.     dummy.l=sendData{<$,Len(lt$)}          ;newtdockdock
  75.     If dummy<-1
  76.      timeout=True
  77.      Goto timeout_jump
  78.     EndIf
  79.     Notify_dock{}
  80.     dummy.l=receiveData{&buf$,Len(buf$)}    ;newtdockname
  81.     If dummy<-1
  82.      timeout=True
  83.      Goto timeout_jump
  84.     EndIf
  85.     Notify_name{&buf$,dummy}
  86.     dummy.l=sendData{<2$,Len(lt2$)}        ;newtdockstim
  87.     If dummy<-1
  88.      timeout=True
  89.      Goto timeout_jump
  90.     EndIf
  91.     Notify_timeoutset{}
  92.  
  93.     dummy.l=receiveData{&buf$,Len(buf$)}    ;newtdockdres
  94.     If dummy<-1
  95.      timeout=True
  96.      Goto timeout_jump
  97.     EndIf
  98.     Notify_resultreceived{}
  99.     file_length.l=Lof(0)
  100.     Notify_loading{package$}
  101.     Notify_filelength{file_length}
  102.     dummy.l=sendData{<3$,Len(lt3$)}        ;newtdocklpkg
  103.     If dummy<-1
  104.      timeout=True
  105.      Goto timeout_jump
  106.     EndIf
  107.     Notify_transferring{}
  108.     ReadMem 0,&buf$,Len(buf$)
  109.     rr.l=0
  110.     size.l=0
  111.     If Lof(0)<Len(buf$)
  112.      rr=Lof(0)
  113.     Else
  114.      rr=Len(buf$)
  115.     EndIf
  116.     size=rr
  117.     Notify_progress{size}
  118.     dummy.l=sendData{&buf$,rr}
  119.     If dummy<-1
  120.      timeout=True
  121.      Goto timeout_jump
  122.     EndIf
  123.  
  124.     While (rr=Len(buf$)) AND (timeout=False)
  125.      ReadMem 0,&buf$,Len(buf$)
  126.      If Eof(0)
  127.       rr=file_length-size         ;reading the file length lof(0) at
  128.                                   ;this point results in an error because lof(0) is
  129.      Else                         ;one more byte than the file's true size!
  130.       rr=Len(buf$)
  131.      EndIf
  132.  
  133.      size+rr
  134.      Notify_progress{size}
  135.      If (rr&3)>0                  ;file length is not an evenly divisible by four
  136.       Notify_padding{}
  137.       rr2.l=(rr+4)&$fffffffc      ;round up file length
  138.       For i=rr+1 To rr2           ;fill with zeros
  139.        Poke &buf$+i,0
  140.       Next i
  141.       rr=rr2
  142.      EndIf
  143.      If rr>0 Then dummy.l=sendData{&buf$,rr}
  144.      If dummy<-1 Then timeout=True
  145.     Wend
  146.  
  147.     If timeout=True Then Goto timeout_jump  ; flag tripped by data sending routine
  148.  
  149.     Notify_finished{}
  150.     dummy.l=receiveData{&buf$,Len(buf$)}    ; newtdockdres
  151.     If dummy<-1
  152.      timeout=True
  153.      Goto timeout_jump
  154.     EndIf
  155.     Notify_resultreceived{}
  156.     dummy.l=sendData{<4$,Len(lt4$)}      ; newtdockdisc
  157.     If dummy<-1
  158.      timeout=True
  159.      Goto timeout_jump
  160.     EndIf
  161.     Notify_disconnecting{}
  162.     VWait 50
  163.     sendDisconnect{}
  164.  
  165.     timeout_jump:
  166.     If timeout=True
  167.      Notify_timeout{}
  168.     EndIf
  169.  
  170.     Notify_disconnected{}
  171.  
  172.     CloseFile 0
  173.    Else
  174.     Notify_nofile{}
  175.    EndIf
  176.    While ReadSerial(0)>=0:Wend ; flush out the input buffer
  177.    CloseSerial 0
  178.   Else
  179.    Notify_noserial{}
  180.   EndIf
  181. CNIF #cli_only=0
  182.   If gui_on
  183.    still_running=get_gui_args{}
  184.   Else
  185. CEND
  186.    still_running=False ; only run once if CLI arguments used
  187. CNIF #cli_only=0
  188.   EndIf
  189. CEND
  190. Wend
  191.  
  192. End
  193.  
  194.  
  195.  
  196.  
  197.